package cn.wolfcode.wolf2world.web.controller;

import cn.wolfcode.wolf2world.domain.Banner;
import cn.wolfcode.wolf2world.domain.Strategy;
import cn.wolfcode.wolf2world.domain.Travel;
import cn.wolfcode.wolf2world.query.BannerQueryObject;
import cn.wolfcode.wolf2world.service.BannerService;
import cn.wolfcode.wolf2world.service.StrategyService;
import cn.wolfcode.wolf2world.service.TravelService;
import cn.wolfcode.wolf2world.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 杨兴健
 * @Date 2020/8/19 18:42
 */
@Controller
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;
    @Autowired
    private StrategyService strategyService;
    @Autowired
    private TravelService travelService;

    @RequestMapping("/list")
    private Object list(Model modle, BannerQueryObject qo) {
        Page<Banner> page = bannerService.query(qo);
        modle.addAttribute("page",page);
        return "/banner/list";
    }

    @RequestMapping("/getAllType")
    @ResponseBody
    private Object getAllType(Model model) {
        List<Strategy> strategies = strategyService.list();
        List<Travel> travels = travelService.list();
        Map map = new HashMap();
        map.put("sts",strategies);
        map.put("ts",travels);
        return JsonResult.success(map);
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner) {
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        bannerService.delete(id);
        return JsonResult.success();
    }

}
